// Mechanicoder
// 2022/11/13

#pragma once

#include <QMainWindow>

#include <AIS_InteractiveContext.hxx>

#include <vector>

class AIS_InteractiveObject;
class View;
enum ContextType;

class QPushButton;

namespace Ui
{
    class CtrlWidgetUi;
}

class ViewWindow : public QMainWindow
{
    Q_OBJECT
public:
    ViewWindow(QWidget* parent = nullptr);
    ~ViewWindow();

private slots:
    void OnHideShape();
    // 随机绘制图形，并根据类型分别由不同的 context 管理
    void OnRandomGeneration();

private:
    void InitCtrlWidget();

    // 添加测试模型
    void GenerateTopoBox(const Handle(AIS_InteractiveContext)& curr_context);
    void GenerateTopoTorus(const Handle(AIS_InteractiveContext)& curr_context);
    void GenerateAISThihedron(const Handle(AIS_InteractiveContext)& curr_context);
    void GenerateTopoSphere(const Handle(AIS_InteractiveContext)& curr_context);
    void GenerateAISPointCloud(const Handle(AIS_InteractiveContext)& curr_context);

    // 根据类型（type非负有效）或随机获取当前视图环境
    Handle(AIS_InteractiveContext) GetCurrentContext(int type = -1) const;

    ContextType CurrentContextType() const;

    // 按钮文字：控制类型、元素数量
    QString MakeHideButtonText(ContextType type, int obj_num) const;

    QString TypeToString(ContextType type) const;

    gp_Dir GenRandomDir() const;

    gp_XYZ GenRandomXYZ() const;

    // 随机生成数
    std::vector<double> GenRandomValues(int num) const;

    double GetRandomValue() const;

    void DisplayShape(const Handle(AIS_InteractiveContext)& curr_contex, const TopoDS_Shape& shape) const;

private:
    std::vector<Handle(AIS_InteractiveContext)> _contexts;
    std::vector<QPushButton*> _hideButtons;

    View* _view;
    View* _rightView;
    Ui::CtrlWidgetUi* _ctrlUi;

    std::vector<Handle(AIS_InteractiveObject)> _generated;
};
